package com.hddf.project.service;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.hibernate.Session;
import org.kommii.mysql_conn_pool.SessionProvider;

import com.hddf.project.base.BaseService;
import com.hddf.project.dao.CommentDao;
import com.hddf.project.dao.ProjectDao;
import com.hddf.project.impl.CommentDaoImpl;
import com.hddf.project.impl.ProjectDaoImpl;
import com.hddf.project.pojos.FirstCategory;
import com.hddf.project.pojos.Project;
import com.hddf.project.pojos.ProjectApproval;
import com.hddf.project.pojos.ProjectCheck;
import com.hddf.project.pojos.ProjectDoc;
import com.hddf.project.pojos.ProjectImg;
import com.hddf.project.pojos.ProjectOther;
import com.hddf.project.pojos.ProjectPlanItem;
import com.hddf.project.pojos.ProjectTable;
import com.hddf.project.pojos.ProjectVideo;
import com.hddf.project.pojos.SecondCategory;
import com.hddf.project.pojos.ThirdCategory;
import com.hddf.project.pojos.User;
import com.hddf.project.util.O;
import com.hddf.project.util.Stct;

public class ProjectService extends BaseService {

	private static ProjectService ps = null;
	private static ProjectDao pd = null;
	private static CategoryService cs = null;
	private static UploadService us = null;
	private static CommentService cts = null;
	private static CommentDao ctd = null;

	static {
		if (null == ps) {
			ps = new ProjectService();
		}
		if (null == pd) {
			pd = new ProjectDaoImpl();
		}
		if (null == cs) {
			cs = CategoryService.getInService();
		}
		if (null == us) {
			us = UploadService.getInService();
		}
		if (null == cts) {
			cts = CommentService.getInService();
		}
		if (null == ctd) {
			ctd = new CommentDaoImpl();
		}
	}

	public static ProjectService getInService() {
		return ps;
	}

	/**
	 * 根据三级ID获取项目数量
	 * 
	 * @param t_id
	 * @return
	 */
	public int getCountByThirdCategory(Integer t_id) throws Exception {
		Session s = null;
		try {
			int result = 0;
			s = SessionProvider.getSession();
			result = pd.getProjectsCountByThirdCategory(t_id, s);
			SessionProvider.commitSession(s);
			return result;
		} catch (Exception e) {
			SessionProvider.rollback(s);
			throw new Exception(e);
		}
	}

	/**
	 * 根据三级ID获取项目
	 * 
	 * @param t_id
	 * @return
	 */
	public List<Project> getProjectsByThirdCategory(Integer t_id) throws Exception {
		Session s = null;
		try {
			List<Project> list = null;
			s = SessionProvider.getSession();
			list = pd.getProjectsByThirdCategory(t_id, 0, 0, s);
			SessionProvider.commitSession(s);
			return list;
		} catch (Exception e) {
			SessionProvider.rollback(s);
			throw new Exception(e);
		}
	}

	/**
	 * 查询全部项目的数量
	 * 
	 * @param s
	 * @return
	 */
	public Integer getAllProject() throws Exception {
		Session s = null;
		try {
			int result = 0;
			s = SessionProvider.getSession();
			result = pd.getAllProject(s);
			SessionProvider.commitSession(s);
			return result;
		} catch (Exception e) {
			SessionProvider.rollback(s);
			throw new Exception(e);
		}
	}

	/**
	 * 添加项目
	 * 
	 * @param f_id
	 *            :一级类别
	 * @param s_id
	 *            :二级类别
	 * @param t_id
	 *            :三级类别
	 * @param projectName
	 *            :项目名称
	 * @param fundPlan
	 *            :资金来源
	 * @param fund
	 *            :总投资
	 * @param implTime
	 *            :项目实施时间
	 * @param area
	 *            :区域
	 * @param plan
	 *            :项目状态(储备，在建，完成)
	 * @param remarks
	 *            :形象进度及完成投资情况
	 * @param description
	 *            :项目概况
	 * @param mgrDepart
	 *            :项目主管部门
	 * @param buildSide
	 *            :建设主体
	 * @param user
	 *            :用户数据
	 * @return
	 * @throws Exception
	 */
	public Project addProject(Integer f_id, Integer s_id, Integer t_id, String projectName, String fundPlan,
			double fund, String implTime, String area, String plan, String remarks, String description,
			String mgrDepart, String buildSide, String sign, User user) {
		Project p = new Project();
		p.setArea(area);
		p.setBuild_side(buildSide);
		p.setFirst_category_id(f_id);
		p.setFund(fund);
		p.setFund_plan(fundPlan);
		p.setImpl_time(implTime);
		p.setInput_time(O.getTimestamp3());
		p.setName(projectName);
		p.setPlan(plan);
		p.setRemarks(remarks);
		p.setSecond_category_id(s_id);
		p.setThird_category_id(t_id);
		p.setUpdate_time(O.getTimestamp3());
		p.setDescription(description);
		p.setMgr_depart(mgrDepart);
		p.setUser_id(user.getId());
		p.setIspass(Stct.ISPASS_NOT);
		p.setHistory(Stct.HISTORY_NOT);
		p.setCheckout((short) 1);
		p.setComment((short) 1);
		p.setSign(sign);
		super.addObject(p);

		return p;
	}

	/**
	 * 将项目修改为未校验状态
	 * 
	 * @param p_id
	 */
	private void checkOut(int p_id) {
		try {
			Project p = (Project) super.getObjectById(p_id, Project.class);
			if (null != p) {
				p.setCheckout((short) 1);
				super.updateObject(p);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 添加说明书
	 * 
	 * @param pathDoc
	 * @param p_id
	 * @throws Exception
	 */
	public void addDoc(Integer p_id, String endPath, List<String> nameList) throws Exception {
		if (null != nameList && !nameList.isEmpty()) {
			for (int i = 0; i < nameList.size(); i++) {
				String fileName = nameList.get(i);
				String[] name = fileName.split(":::");
				String realName = name[0];// 真实的名字
				String uuidName = name[1];// 上传后的名字

				String path = endPath + "/" + uuidName;
				ProjectDoc pD = new ProjectDoc();
				pD.setDocSrc(path);
				pD.setProjectId(p_id);
				pD.setDocName(realName);
				super.addObject(pD);

				transformDocument(path, uuidName);
			}
			this.checkOut(p_id);
		}
	}

	/**
	 * 添加设计图
	 */
	public void addImg(Integer p_id, String endPath, List<String> nameList) throws Exception {
		if (null != nameList && !nameList.isEmpty()) {
			for (int i = 0; i < nameList.size(); i++) {
				String fileName = nameList.get(i);
				String[] name = fileName.split(":::");
				String realName = name[0];// 真实的名字
				String uuidName = name[1];// 上传后的名字

				ProjectImg pi = new ProjectImg();
				pi.setImgSrc(endPath + "/" + uuidName);
				pi.setProjectId(p_id);
				pi.setImgName(realName);
				super.addObject(pi);
			}
			this.checkOut(p_id);
		}
	}

	/**
	 * 添加三表
	 */
	public void addTable(Integer p_id, String endPath, List<String> nameList) throws Exception {
		if (null != nameList && !nameList.isEmpty()) {
			for (int i = 0; i < nameList.size(); i++) {
				String fileName = nameList.get(i);
				String[] name = fileName.split(":::");
				String realName = name[0];// 真实的名字
				String uuidName = name[1];// 上传后的名字

				String path = endPath + "/" + uuidName;
				ProjectTable pt = new ProjectTable();
				pt.setProjectId(p_id);
				pt.setTableSrc(path);
				pt.setTableName(realName);
				super.addObject(pt);

				transformDocument(path, uuidName);
			}
			this.checkOut(p_id);
		}
	}

	/**
	 * 添加批件
	 */
	public void addApproval(Integer p_id, String endPath, List<String> nameList) throws Exception {
		if (null != nameList && !nameList.isEmpty()) {
			for (int i = 0; i < nameList.size(); i++) {
				String fileName = nameList.get(i);
				String[] name = fileName.split(":::");
				String realName = name[0];// 真实的名字
				String uuidName = name[1];// 上传后的名字

				ProjectApproval pa = new ProjectApproval();
				pa.setProjectId(p_id);
				pa.setApprovalSrc(endPath + "/" + uuidName);
				pa.setApprovalName(realName);
				super.addObject(pa);
			}
			this.checkOut(p_id);
		}
	}

	/**
	 * 添加部门意见
	 */
	public void addCheck(Integer p_id, String endPath, List<String> nameList) throws Exception {
		if (null != nameList && !nameList.isEmpty()) {
			for (int i = 0; i < nameList.size(); i++) {
				String fileName = nameList.get(i);
				String[] name = fileName.split(":::");
				String realName = name[0];// 真实的名字
				String uuidName = name[1];// 上传后的名字

				String path = endPath + "/" + uuidName;
				ProjectCheck pc = new ProjectCheck();
				pc.setProjectId(p_id);
				pc.setCheckSrc(path);
				pc.setCheckName(realName);
				super.addObject(pc);

				// transformDocument(path, uuidName);
			}
			this.checkOut(p_id);
		}
	}

	/**
	 * 添加部门意见
	 */
	public void addVideo(Integer p_id, String endPath, List<String> nameList) throws Exception {
		if (null != nameList && !nameList.isEmpty()) {
			for (int i = 0; i < nameList.size(); i++) {
				String fileName = nameList.get(i);
				String[] name = fileName.split(":::");
				String realName = name[0];// 真实的名字
				String uuidName = name[1];// 上传后的名字

				String path = endPath + "/" + uuidName;
				ProjectVideo pv = new ProjectVideo();
				pv.setProjectId(p_id);
				pv.setVideoSrc(path);
				pv.setVideoName(realName);
				super.addObject(pv);

				// transformDocument(path, uuidName);
			}
			this.checkOut(p_id);
		}
	}

	/**
	 * 添加其他文件
	 */
	public void addOther(Integer p_id, String endPath, List<String> nameList) throws Exception {
		if (null != nameList && !nameList.isEmpty()) {
			for (int i = 0; i < nameList.size(); i++) {
				String fileName = nameList.get(i);
				String[] name = fileName.split(":::");
				String realName = name[0];// 真实的名字
				String uuidName = name[1];// 上传后的名字

				String path = endPath + "/" + uuidName;
				ProjectOther po = new ProjectOther();
				po.setProjectId(p_id);
				po.setOtherSrc(path);

				int type = 0;
				String suffix = realName.substring(realName.lastIndexOf(".") + 1).toLowerCase();
				if (suffix.equals("jpg") || suffix.equals("png") || suffix.equals("gif") || suffix.equals("jpeg")
						|| suffix.equals("bmp")) {
					type = 1;
				} else if (suffix.equals("pdf")) {
					type = 2;
				} else if (suffix.equals("xls") || suffix.equals("xlsx") || suffix.equals("xlsm")
						|| suffix.equals("xltx") || suffix.equals("xltm") || suffix.equals("xlsb")
						|| suffix.equals("xlam")) {
					type = 3;
				} else if (suffix.equals("doc") || suffix.equals("docx") || suffix.equals("dot")
						|| suffix.equals("dotx") || suffix.equals("docm") || suffix.equals("dotm")
						|| suffix.equals("xml")) {
					type = 4;
				} else if (suffix.equals("dwg") || suffix.equals("dwt")) {
					type = 5;
				} else {
					type = 6;
				}
				po.setType(type);
				po.setOtherName(realName);
				super.addObject(po);

				// transformDocument(path, uuidName);
			}
			this.checkOut(p_id);
		}
	}

	/**
	 * 根据类别ID等条件获取项目数量
	 */
	public List<Project> getProjectsByCategory(Integer startData, Integer lengthData, Integer f_id, Integer s_id,
			Integer t_id, String projectName, String startTime, String endTime, String startFund, String endFund,
			String mgrDepart, String buildSide, String plan, String area, Short ispass, Short comment,
			Short checkout, Integer userid) throws Exception {
		Session s = null;
		try {
			List<Project> pList = null;
			List<String> areaList = new LinkedList<String>();
			if (O.ckSt(area)) {
				if (-1 != area.indexOf(",")) {
					String[] _area = area.split(",");
					for (int i = 0; i < _area.length; i++) {
						areaList.add(_area[i]);
					}
				} else {
					areaList.add(area);
				}
			}
			s = SessionProvider.getSession();
			pList = pd.getProjectListByMoreConditions(startData, lengthData, f_id, s_id, t_id, projectName,
					startTime, endTime, startFund, endFund, mgrDepart, buildSide, plan, areaList, ispass, comment,
					checkout, s);

			// if (0 != userid && O.ckLt(pList)) {
			// for (Project p : pList) {
			// if (null != p.getComment() && p.getComment() == 2) {
			// p.setCommentv(ctd.commentDetail(userid, p.getId(), s));
			// }
			// }
			// }
			SessionProvider.commitSession(s);
			return pList;
		} catch (Exception e) {
			SessionProvider.rollback(s);
			throw new Exception(e);
		}
	}

	/**
	 * 根据类别ID等条件获取项目数量
	 * 
	 * @param f_id
	 *            :第一类别
	 * @param s_id
	 *            :第二类别
	 * @param t_id
	 *            :第三类别
	 * @param projectName
	 *            :项目名称
	 * @param startTime
	 *            :开始时间
	 * @param endTime
	 *            :结束时间
	 * @param startFund
	 *            :起始总额
	 * @param endFund
	 *            :最大总额
	 * @param mgrDepart
	 *            :主管部门
	 * @param buildSide
	 *            :建设主体
	 * @param plan
	 *            :项目状态
	 * @param area
	 *            :地区
	 * @param ispass
	 *            :列入计划
	 * @param comment
	 *            :是否批示
	 * @param checkout
	 *            :是否校验
	 * @return
	 * @throws Exception
	 */
	public Integer getProjectsCountByMoreConditions(Integer f_id, Integer s_id, Integer t_id, String projectName,
			String startTime, String endTime, String startFund, String endFund, String mgrDepart,
			String buildSide, String plan, String area, Short ispass, Short comment, Short checkout)
			throws Exception {
		Session s = null;
		try {
			int result = 0;
			List<String> areaList = new LinkedList<String>();
			if (O.ckSt(area)) {
				if (-1 != area.indexOf(",")) {
					String[] _area = area.split(",");
					for (int i = 0; i < _area.length; i++) {
						areaList.add(_area[i]);
					}
				} else {
					areaList.add(area);
				}
			}
			s = SessionProvider.getSession();
			result = pd.getProjectsCountByMoreConditions(f_id, s_id, t_id, projectName, startTime, endTime,
					startFund, endFund, mgrDepart, buildSide, plan, areaList, ispass, comment, checkout, s);
			SessionProvider.commitSession(s);
			return result;
		} catch (Exception e) {
			SessionProvider.rollback(s);
			throw new Exception(e);
		}
	}

	/**
	 * 根据二级分类ID获取项目
	 * 
	 * @param f_id
	 * @param s
	 * @return
	 * @throws Exception
	 */
	public List<Project> getAllProjects(Integer startData, Integer lengthData) throws Exception {
		Session s = null;
		try {
			List<Project> pList = null;
			s = SessionProvider.getSession();
			pList = pd.getAllProjects(startData, lengthData, s);
			SessionProvider.commitSession(s);
			return pList;
		} catch (Exception e) {
			SessionProvider.rollback(s);
			throw new Exception(e);
		}
	}

	/**
	 * 根据ID获取项目
	 * 
	 * @param p_id
	 * @return
	 */
	public Project getProjectById(Integer p_id) throws Exception {
		return (Project) super.getObjectById(p_id, Project.class);
	}

	/**
	 * 根据ID获取项目明细
	 * 
	 * @param p_id
	 * @return
	 */
	public Project getProjectDetailedById(Integer p_id) throws Exception {
		Project p = this.getProjectById(p_id);
		if (null != p) {
			if (null != p.getFirst_category_id() && p.getFirst_category_id() != 0) {
				FirstCategory fc = cs.getFirstCategory(p.getFirst_category_id());
				p.setFirstCategoryName(fc.getFirst_category_name());
			}
			if (null != p.getThird_category_id() && p.getSecond_category_id() != 0) {
				SecondCategory sc = cs.getSecondCategory(p.getSecond_category_id());
				p.setSecondCategoryName(sc.getSecond_category_name());
			}
			if (null != p.getThird_category_id() && p.getThird_category_id() != 0) {
				ThirdCategory tc = cs.getThirdCategory(p.getThird_category_id());
				p.setThirdCategoryName(tc.getThird_category_name());
			}
			if (O.ckSt(p.getPath())) {
				List<ProjectDoc> docList = this.getDocsByProjectId(p_id);
				p.setDocList(docList);
				List<ProjectImg> imgList = this.getImgsByProjectId(p_id);
				p.setImgList(imgList);
				List<ProjectTable> tableList = this.getTablesByProjectId(p_id);
				p.setTableList(tableList);
				List<ProjectApproval> approvalList = this.getApprovalsByProjectId(p_id);
				p.setApprovalList(approvalList);
				List<ProjectCheck> checkList = this.getChecksByProjectId(p_id);
				p.setCheckList(checkList);
				List<ProjectVideo> videoList = this.getVideoByProjectId(p_id);
				p.setVideoList(videoList);
				List<ProjectOther> otherList = this.getOtherByProjectId(p_id);
				p.setOtherList(otherList);
			}

			if (null != p.getComment() && p.getComment() == 2) {
				p.setCommentList(cts.listComment(p.getId()));
			}
		}
		return p;
	}

	/**
	 * 根据项目ID获取部门意见
	 * 
	 * @param p_id
	 * @return
	 */
	public List<ProjectCheck> getChecksByProjectId(Integer p_id) throws Exception {
		Session s = null;
		try {
			s = SessionProvider.getSession();
			List<ProjectCheck> p = pd.getChecksByProjectId(p_id, s);
			SessionProvider.commitSession(s);
			return p;
		} catch (Exception e) {
			SessionProvider.rollback(s);
			throw new Exception(e);
		}
	}

	/**
	 * 根据项目ID获取部门意见
	 * 
	 * @param p_id
	 * @return
	 */
	public List<ProjectVideo> getVideoByProjectId(Integer p_id) throws Exception {
		Session s = null;
		try {
			s = SessionProvider.getSession();
			List<ProjectVideo> pv = pd.getVideoByProjectId(p_id, s);
			SessionProvider.commitSession(s);
			return pv;
		} catch (Exception e) {
			SessionProvider.rollback(s);
			throw new Exception(e);
		}
	}

	/**
	 * 根据项目ID获取说明书
	 */
	public List<ProjectDoc> getDocsByProjectId(Integer p_id) throws Exception {
		Session s = null;
		try {
			s = SessionProvider.getSession();
			List<ProjectDoc> p = pd.getDocsByProjectId(p_id, s);
			SessionProvider.commitSession(s);
			return p;
		} catch (Exception e) {
			SessionProvider.rollback(s);
			throw new Exception(e);
		}
	}

	/**
	 * 根据项目ID设计图
	 */
	public List<ProjectImg> getImgsByProjectId(Integer p_id) throws Exception {
		Session s = null;
		try {
			s = SessionProvider.getSession();
			List<ProjectImg> p = pd.getImgsByProjectId(p_id, s);
			SessionProvider.commitSession(s);
			return p;
		} catch (Exception e) {
			SessionProvider.rollback(s);
			throw new Exception(e);
		}
	}

	/**
	 * 根据项目ID三表
	 */
	public List<ProjectTable> getTablesByProjectId(Integer p_id) throws Exception {
		Session s = null;
		try {
			s = SessionProvider.getSession();
			List<ProjectTable> p = pd.getTablesByProjectId(p_id, s);
			SessionProvider.commitSession(s);
			return p;
		} catch (Exception e) {
			SessionProvider.rollback(s);
			throw new Exception(e);
		}
	}

	/**
	 * 根据项目ID批件
	 */
	public List<ProjectApproval> getApprovalsByProjectId(Integer p_id) throws Exception {
		Session s = null;
		try {
			s = SessionProvider.getSession();
			List<ProjectApproval> p = pd.getApprovalsByProjectId(p_id, s);
			SessionProvider.commitSession(s);
			return p;
		} catch (Exception e) {
			SessionProvider.rollback(s);
			throw new Exception(e);
		}
	}

	/**
	 * 根据项目ID获取部门意见
	 * 
	 * @param p_id
	 * @return
	 */
	public List<ProjectOther> getOtherByProjectId(Integer p_id) {
		Session s = null;
		try {
			s = SessionProvider.getSession();
			List<ProjectOther> po = pd.getOtherByProjectId(p_id, s);
			SessionProvider.commitSession(s);
			return po;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

	/**
	 * 转换文档
	 * 
	 * @param endPath
	 * @param uuidName
	 * @param fileName
	 * @param folderName
	 */
	public void transformDocument(String endPath, String uuidName) {
		String upload = Stct.UPLOAD_PATH;
		String beforeUpload = upload.substring(0, upload.indexOf(Stct.UPLOAD_PATH_SAVE));
		endPath = beforeUpload + endPath;
		String fileNameBefore = uuidName.substring(0, uuidName.lastIndexOf("."));// 上传后文件的名字
		String pdfPath = Stct.TRANSFORM_PDF_PATH + fileNameBefore + ".pdf";// pdf路径
		us.office2PDF(endPath, pdfPath);// 转换成pdf
		String swfPath = Stct.TRANSFORM_SWF_PATH + fileNameBefore + ".swf";// swf路径
		us.pdf2SWF(pdfPath, swfPath);// 转换成swf
		us.delFolder(pdfPath);// 删除PDF文件
	}

	/**
	 * 根据文档的ID，整理出显示路径和名字
	 * 
	 * @param scrId
	 * @param srcType
	 * @return
	 * @throws Exception
	 */
	public Map<String, String> getSrc(Integer scrId, Integer srcType) throws Exception {
		Map<String, String> map = new HashMap<String, String>();
		String srcPath = "";
		switch (srcType) {
		case Stct.UPLOAD_TYPE_DOC:
			ProjectDoc p = (ProjectDoc) this.getObjectById(scrId, ProjectDoc.class);
			srcPath = p.getDocSrc();
			map.put("srcName", p.getDocName());
			break;
		case Stct.UPLOAD_TYPE_TABLE:
			ProjectTable pt = (ProjectTable) this.getObjectById(scrId, ProjectTable.class);
			srcPath = pt.getTableSrc();
			map.put("srcName", pt.getTableName());
			break;
		case Stct.UPLOAD_TYPE_CHECK:
			ProjectCheck pc = (ProjectCheck) this.getObjectById(scrId, ProjectCheck.class);
			srcPath = pc.getCheckSrc();
			map.put("srcName", pc.getCheckName());
			break;
		}
		srcPath = srcPath.substring(0, srcPath.lastIndexOf("."));
		srcPath = Stct.BROWSING_PATH + srcPath.substring(srcPath.length() - 32) + ".swf";
		map.put("srcPath", srcPath);
		return map;
	}

	/**
	 * 删除上传
	 */
	public boolean deleleUpload(Integer id, Integer type) throws Exception {
		boolean tof = false;
		boolean isDeleteSwf = false;
		String path = "";
		int p_id = 0;
		switch (type) {
		case Stct.UPLOAD_TYPE_DOC:
			ProjectDoc p = (ProjectDoc) super.getObjectById(id, ProjectDoc.class);
			path = p.getDocSrc();
			p_id = p.getProjectId();
			tof = super.deleteObject(p);
			break;
		case Stct.UPLOAD_TYPE_IMG:
			ProjectImg pi = (ProjectImg) super.getObjectById(id, ProjectImg.class);
			path = pi.getImgSrc();
			p_id = pi.getProjectId();
			tof = super.deleteObject(pi);
			break;
		case Stct.UPLOAD_TYPE_TABLE:
			ProjectTable pt = (ProjectTable) super.getObjectById(id, ProjectTable.class);
			path = pt.getTableSrc();
			p_id = pt.getProjectId();
			isDeleteSwf = true;
			tof = super.deleteObject(pt);
			break;
		case Stct.UPLOAD_TYPE_APPROVAL:
			ProjectApproval pa = (ProjectApproval) super.getObjectById(id, ProjectApproval.class);
			path = pa.getApprovalSrc();
			p_id = pa.getProjectId();
			isDeleteSwf = true;
			tof = super.deleteObject(pa);
			break;
		case Stct.UPLOAD_TYPE_CHECK:
			ProjectCheck pc = (ProjectCheck) this.getObjectById(id, ProjectCheck.class);
			path = pc.getCheckSrc();
			p_id = pc.getProjectId();
			tof = super.deleteObject(pc);
			break;
		case Stct.UPLOAD_TYPE_VIDEO:
			ProjectVideo pv = (ProjectVideo) this.getObjectById(id, ProjectVideo.class);
			path = pv.getVideoSrc();
			p_id = pv.getProjectId();
			tof = super.deleteObject(pv);
			break;
		case Stct.UPLOAD_TYPE_OTHER:
			ProjectOther po = (ProjectOther) this.getObjectById(id, ProjectOther.class);
			path = po.getOtherSrc();
			p_id = po.getProjectId();
			tof = super.deleteObject(po);
			break;
		}
		if (tof) {
			us.delFolder(Stct.UPLOAD + path);
			this.checkOut(p_id);
		}
		if (isDeleteSwf) {
			path = Stct.TRANSFORM_SWF_PATH + path.substring(Stct.UPLOAD_PATH_SAVE.length());
			us.delFolder(path);
		}
		return tof;
	}

	/**
	 * 修改项目
	 * 
	 * @param p
	 * @param s
	 */
	public Project updateProject(Integer f_id, Integer s_id, Integer t_id, String projectName, String buildSide,
			String fundPlan, double fund, String implTime, String area, String plan, String remarks,
			String description, String mgrDepart, Integer id, String sign) {
		Project _p = (Project) this.getObjectById(id, Project.class);

		Project p = (Project) this.getObjectById(id, Project.class);
		p.setArea(area);
		p.setBuild_side(buildSide);
		p.setFirst_category_id(f_id);
		p.setFund(fund);
		p.setFund_plan(fundPlan);
		p.setImpl_time(implTime);
		p.setName(projectName);
		p.setPlan(plan);
		p.setRemarks(remarks);
		p.setSecond_category_id(s_id);
		p.setThird_category_id(t_id);
		p.setUpdate_time(O.getTimestamp3());
		p.setDescription(description);
		p.setMgr_depart(mgrDepart);
		p.setSign(sign);

		if (p != _p) {
			p.setCheckout((short) 1);
		}

		int nowYear = Integer.valueOf(O.getTimestamp3().substring(0, 4));
		int implYear = Integer.valueOf(implTime.substring(0, 4));
		if (implYear < nowYear) {
			p.setHistory(Stct.HISTORY_IS);
		} else {
			p.setHistory(Stct.HISTORY_NOT);
		}
		super.updateObject(p);
		return p;
	}

	/**
	 * 删除项目
	 * 
	 * @param id
	 * @return
	 * @throws Exception
	 */
	public void deleteProject(Integer id) throws Exception {
		Project p = (Project) this.getObjectById(id, Project.class);
		if (null != p && 0 != p.getId()) {
			if (O.ckSt(p.getPath())) {
				us.delFolder(Stct.UPLOAD + p.getPath());
				us.delFolder(Stct.TRANSFORM_SWF_PATH + p.getPath().substring(Stct.UPLOAD_PATH_SAVE.length()));
			}
			super.deleteObject(p);

			List<ProjectDoc> pdList = this.getDocsByProjectId(id);
			if (O.ckLt(pdList)) {
				for (int i = 0; i < pdList.size(); i++) {
					ProjectDoc pD = pdList.get(i);
					super.deleteObject(pD);
				}
			}
			List<ProjectImg> piLIst = this.getImgsByProjectId(id);
			if (O.ckLt(piLIst)) {
				for (int i = 0; i < piLIst.size(); i++) {
					ProjectImg pi = piLIst.get(i);
					super.deleteObject(pi);
				}
			}
			List<ProjectTable> ptList = this.getTablesByProjectId(id);
			if (O.ckLt(pdList)) {
				for (int i = 0; i < ptList.size(); i++) {
					ProjectTable pt = ptList.get(i);
					super.deleteObject(pt);
				}
			}

			List<ProjectApproval> paList = this.getApprovalsByProjectId(id);
			if (O.ckLt(paList)) {
				for (int i = 0; i < paList.size(); i++) {
					ProjectApproval pa = paList.get(i);
					super.deleteObject(pa);
				}
			}

			PlanService planService = PlanService.getInService();
			List<ProjectPlanItem> ppiList = planService.getPlanItemByProjectId(p.getId());
			if (O.ckLt(ppiList)) {
				for (ProjectPlanItem ppi : ppiList) {
					super.deleteObject(ppi);
				}
			}
		}
	}

	/**
	 * 根据一级分类ID获取对应的项目数量
	 * 
	 * @param f_id
	 * @return
	 * @throws Exception
	 */
	public Integer getProjectCountByCategoryFirst(Integer f_id) throws Exception {
		Session s = null;
		try {
			int result = 0;
			s = SessionProvider.getSession();
			result = pd.getProjectCountByCategoryFirst(f_id, s);
			SessionProvider.commitSession(s);
			return result;
		} catch (Exception e) {
			SessionProvider.rollback(s);
			throw new Exception(e);
		}
	}

	/**
	 * 根据一级分类ID获取对应的项目数量
	 * 
	 * @param f_id
	 * @return
	 * @throws Exception
	 */
	public int getProjectsCountBySecondCategory(Integer s_id, String plan) {
		Session s = null;
		try {
			int result = 0;
			s = SessionProvider.getSession();
			result = pd.getProjectsCountBySecondCategory(s_id, plan, s);
			SessionProvider.commitSession(s);
			return result;
		} catch (Exception e) {
			SessionProvider.rollback(s);
			e.printStackTrace();
			return 0;
		}
	}

	/**
	 * 根据近期、远期、历史查询项目数量
	 */
	public List<Integer> getProjectsCountByTime() throws Exception {
		List<Integer> list = new LinkedList<Integer>();
		int near = this.getProjectsCountByMoreConditions(0, 0, 0, null, null, null, null, null, null, null, "储备",
				null, (short) 0, (short) 0, (short) 0);
		list.add(near);
		int distance = this.getProjectsCountByMoreConditions(0, 0, 0, null, null, null, null, null, null, null,
				"在建", null, (short) 0, (short) 0, (short) 0);
		list.add(distance);
		int history = this.getProjectsCountByMoreConditions(0, 0, 0, null, null, null, null, null, null, null,
				"完成", null, (short) 0, (short) 0, (short) 0);
		list.add(history);
		return list;
	}

	/**
	 * 批注处理
	 */
	public boolean projectNotation(Integer p_id, String comment) throws Exception {
		Project p = this.getProjectById(p_id);
		if (null != p) {
			p.setComment((short) 2);
			p.setUpdate_time(O.getTimestamp3());
			super.updateObject(p);
			return true;
		}
		return false;
	}

	/**
	 * 根据名字和项目ID查询批件
	 * 
	 * @param uploadName
	 * @param s
	 * @return
	 * @throws Exception
	 */
	public ProjectApproval getApprovalByUploadName(Integer projectId, String uploadName) throws Exception {
		Session s = null;
		try {
			s = SessionProvider.getSession();
			ProjectApproval pa = pd.getApprovalByUploadName(projectId, uploadName, s);
			SessionProvider.commitSession(s);
			return pa;
		} catch (Exception e) {
			SessionProvider.rollback(s);
			throw new Exception(e);
		}
	}

	/**
	 * 根据名字和项目ID查询意见
	 * 
	 * @param uploadName
	 * @param s
	 * @return
	 * @throws Exception
	 */
	public ProjectCheck getCheckByUploadName(Integer projectId, String uploadName) throws Exception {
		Session s = null;
		try {
			s = SessionProvider.getSession();
			ProjectCheck pc = pd.getCheckByUploadName(projectId, uploadName, s);
			SessionProvider.commitSession(s);
			return pc;
		} catch (Exception e) {
			SessionProvider.rollback(s);
			throw new Exception(e);
		}
	}

	/**
	 * 根据名字和项目ID查询文档
	 * 
	 * @param uploadName
	 * @param s
	 * @return
	 * @throws Exception
	 */
	public ProjectDoc getDocByUploadName(Integer projectId, String uploadName) throws Exception {
		Session s = null;
		try {
			s = SessionProvider.getSession();
			ProjectDoc p = pd.getDocByUploadName(projectId, uploadName, s);
			SessionProvider.commitSession(s);
			return p;
		} catch (Exception e) {
			SessionProvider.rollback(s);
			throw new Exception(e);
		}
	}

	/**
	 * 根据名字和项目ID查询图片
	 * 
	 * @param uploadName
	 * @param s
	 * @return
	 * @throws Exception
	 */
	public ProjectImg getImgByUploadName(Integer projectId, String uploadName) throws Exception {
		Session s = null;
		try {
			s = SessionProvider.getSession();
			ProjectImg pi = pd.getImgByUploadName(projectId, uploadName, s);
			SessionProvider.commitSession(s);
			return pi;
		} catch (Exception e) {
			SessionProvider.rollback(s);
			throw new Exception(e);
		}
	}

	/**
	 * 根据名字和项目ID查询三表
	 * 
	 * @param uploadName
	 * @param s
	 * @return
	 * @throws Exception
	 */
	public ProjectTable getTableByUploadName(Integer projectId, String uploadName) throws Exception {
		Session s = null;
		try {
			s = SessionProvider.getSession();
			ProjectTable pt = pd.getTableByUploadName(projectId, uploadName, s);
			SessionProvider.commitSession(s);
			return pt;
		} catch (Exception e) {
			SessionProvider.rollback(s);
			throw new Exception(e);
		}
	}

	/**
	 * 根据名字和项目ID查询意见
	 * 
	 * @param uploadName
	 * @param s
	 * @return
	 * @throws Exception
	 */
	public ProjectVideo getVideoByUploadName(Integer projectId, String uploadName) throws Exception {
		Session s = null;
		try {
			s = SessionProvider.getSession();
			ProjectVideo pv = pd.getVideoByUploadName(projectId, uploadName, s);
			SessionProvider.commitSession(s);
			return pv;
		} catch (Exception e) {
			SessionProvider.rollback(s);
			throw new Exception(e);
		}
	}

	/**
	 * 根据名字和项目ID查询其他文件
	 * 
	 * @param uploadName
	 * @param s
	 * @return
	 * @throws Exception
	 */
	public ProjectOther getOtherByUploadName(Integer projectId, String uploadName) {
		Session s = null;
		try {
			s = SessionProvider.getSession();
			ProjectOther po = pd.getOtherByUploadName(projectId, uploadName, s);
			SessionProvider.commitSession(s);
			return po;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

	// /**
	// * 查询是否有新更新的批示
	// *
	// * @param s
	// * @return
	// * @throws Exception
	// */
	// public List<CheckAnnotations> getUpdateNotation() throws Exception {
	// Session s = null;
	// try {
	// List<CheckAnnotations> caList = null;
	// s = SessionProvider.getSession();
	// caList = ps.getUpdateNotation();
	// SessionProvider.commitSession(s);
	// return caList;
	// } catch (Exception e) {
	// SessionProvider.rollback(s);
	// throw new Exception(e);
	// }
	// }
	//
	// /**
	// * 根据项目ID查询是否存在更新
	// *
	// * @param projectId
	// * @param s
	// * @return
	// * @throws Exception
	// */
	// public CheckAnnotations getCheckAnnotationsByProjectId(Integer projectId)
	// throws Exception {
	// Session s = null;
	// try {
	// s = SessionProvider.getSession();
	// CheckAnnotations ca = ps.getCheckAnnotationsByProjectId(projectId);
	// SessionProvider.commitSession(s);
	// return ca;
	// } catch (Exception e) {
	// SessionProvider.rollback(s);
	// throw new Exception(e);
	// }
	// }
	//
	// /**
	// * 添加批示更新
	// *
	// * @throws Exception
	// */
	// public void addCheckAnnotations(Integer projectId) throws Exception {
	// CheckAnnotations ca = new CheckAnnotations();
	// ca.setProjectId(projectId);
	// ca.setInput_time(O.getTimestamp3());
	// super.addObject(ca);
	// }

	/**
	 * 根据文档的ID，整理出显示路径和名字
	 * 
	 * @param scrId
	 * @param srcType
	 * @return
	 * @throws Exception
	 */
	public Map<String, String> getDownloadDocument(Integer scrId, Integer srcType) throws Exception {
		Map<String, String> map = new HashMap<String, String>();
		switch (srcType) {
		case Stct.UPLOAD_TYPE_DOC:
			ProjectDoc p = (ProjectDoc) this.getObjectById(scrId, ProjectDoc.class);
			map.put("srcPath", Stct.UPLOAD + p.getDocSrc());
			map.put("srcName", p.getDocName());
			break;
		case Stct.UPLOAD_TYPE_TABLE:
			ProjectTable pt = (ProjectTable) this.getObjectById(scrId, ProjectTable.class);
			map.put("srcPath", Stct.UPLOAD + pt.getTableSrc());
			map.put("srcName", pt.getTableName());
			break;
		case Stct.UPLOAD_TYPE_OTHER:
			ProjectOther po = (ProjectOther) this.getObjectById(scrId, ProjectOther.class);
			map.put("srcPath", Stct.UPLOAD + po.getOtherSrc());
			map.put("srcName", po.getOtherName());
			break;
		}
		return map;
	}

	/**
	 * 校验项目
	 * 
	 * @param id
	 */
	public void projectCheckout(Integer p_id) {
		try {
			Project p = (Project) super.getObjectById(p_id, Project.class);
			if (null != p && p.getCheckout() != 2) {
				p.setCheckout((short) 2);
				super.updateObject(p);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 批量添加项目
	 * 
	 * @param user
	 * @param tempList
	 */
	public void addMoreProjectBasis(User user, List<List<String>> tempList) {
		Session s = null;
		try {
			tempList.remove(0);
			tempList.remove(0);
			tempList.remove(0);
			tempList.remove(0);
			tempList.remove(0);
			tempList.remove(0);
			s = SessionProvider.getSession();
			for (List<String> list : tempList) {
				if (O.ckLt(list) && O.ckSt(list.get(1)) && O.ckSt(list.get(9)) && O.ckSt(list.get(10))
						&& !list.get(9).equals("0.0") && !list.get(9).equals("0") && !list.get(10).equals("0.0")
						&& !list.get(10).equals("0")) {
					String projectName = this.removeSymbols(list.get(1).trim());
					String desc = this.removeSymbols(list.get(8).trim());
					String mgrDepart = this.removeSymbols(list.get(9).trim());
					String buildSide = this.removeSymbols(list.get(10).trim());
					Double fund = null;
					if (O.ckSt(list.get(2))) {
						fund = Double.valueOf(this.removeSymbols(list.get(2).trim()));
					}

					StringBuffer fundPlan = new StringBuffer();
					if (O.ckSt(list.get(12))) {
						fundPlan.append("总计：" + this.removeSymbols(list.get(12)) + "；");
					}
					if (O.ckSt(list.get(13))) {
						fundPlan.append("国家资金投入：" + this.removeSymbols(list.get(13)) + "；");
					}
					if (O.ckSt(list.get(14))) {
						fundPlan.append("省政策资金（含债券）投入：" + this.removeSymbols(list.get(14)) + "；");
					}
					if (O.ckSt(list.get(16))) {
						fundPlan.append("市场化（PPP、BOT）方式投入——结转项目：" + this.removeSymbols(list.get(16)) + "；");
					}
					if (O.ckSt(list.get(17))) {
						fundPlan.append("市场化（PPP、BOT）方式投入——新建项目：" + this.removeSymbols(list.get(17)) + "；");
					}
					if (O.ckSt(list.get(18))) {
						fundPlan.append("地铁、土储及棚改封闭运作投入：" + this.removeSymbols(list.get(18)) + "；");
					}
					if (O.ckSt(list.get(19))) {
						fundPlan.append("市本级投入——市级专项资金投入：" + this.removeSymbols(list.get(19)) + "；");
					}
					if (O.ckSt(list.get(20))) {
						fundPlan.append("市本级投入——市城建资金投入：" + this.removeSymbols(list.get(20)) + "；");
					}
					if (O.ckSt(list.get(21))) {
						fundPlan.append("其他（延续银行贷款渠道）投入：" + this.removeSymbols(list.get(21)) + "；");
					}
					if (O.ckSt(list.get(22))) {
						fundPlan.append("银行倒贷：" + this.removeSymbols(list.get(22)) + "；");
					}
					if (O.ckSt(list.get(23))) {
						fundPlan.append("各区（政策区）投入：" + this.removeSymbols(list.get(23)) + "；");
					}
					if (O.ckSt(list.get(24))) {
						fundPlan.append("企业及社会化投入：" + this.removeSymbols(list.get(24)) + "；");
					}

					String sign = null;
					if (list.size() == 26 && null != list.get(25)) {
						sign = this.removeSymbols(list.get(25));
					}

					Project p = pd.project(projectName, s);

					if (null == p) {
						p = new Project();
					}
					p.setFund_plan(fundPlan.toString());
					p.setFund(fund);
					p.setMgr_depart(mgrDepart);
					p.setBuild_side(buildSide);
					p.setUser_id(user.getId());
					p.setDescription(desc);
					p.setCheckout((short) 1);
					p.setSign(sign);
					p.setUpdate_time(O.getTimestamp3());
					p.setName(projectName);

					if (null != p.getId()) {
						s.update(p);
					} else {
						p.setInput_time(O.getTimestamp3());
						p.setIspass(Stct.ISPASS_NOT);
						p.setHistory(Stct.HISTORY_NOT);
						p.setImpl_time("");
						p.setArea("");
						p.setComment((short) 1);
						p.setPlan("储备");
						s.save(p);
					}
				}
			}
			SessionProvider.commitSession(s);
		} catch (Exception e) {
			SessionProvider.rollback(s);
			e.printStackTrace();
		}
	}

	/**
	 * 批量添加项目详情数据
	 * 
	 * @param user
	 * @param tempList
	 */
	public void addMoreProjectDetail(User user, List<List<String>> tempList) {
		Session s = null;
		try {
			tempList.remove(0);
			tempList.remove(0);
			tempList.remove(0);
			tempList.remove(0);
			tempList.remove(0);
			tempList.remove(0);
			tempList.remove(0);
			s = SessionProvider.getSession();
			for (List<String> list : tempList) {
				if (O.ckLt(list) && O.ckSt(list.get(1))) {
					String projectName = this.removeSymbols(list.get(1).trim());

					String implTime = null;
					if (null != list.get(5) && !list.get(5).equals("") && !list.get(5).equals("0")
							&& !list.get(5).equals("0.0")) {
						implTime = this.removeSymbols(list.get(5).trim());
					}
					String endTime = null;
					if (null != list.get(6) && !list.get(6).equals("") && !list.get(6).equals("0")
							&& !list.get(6).equals("0.0")) {
						endTime = this.removeSymbols(list.get(6).trim());
					}

					String plan = "储备";
					int startYear = 0;
					int startMoonth = 1;
					int endYear = 0;
					int endMoonth = 12;
					String nowTime = O.getTimestamp2();
					int nowYear = Integer.valueOf(nowTime.substring(0, 4));// 现在年
					int nowMoonth = Integer.valueOf(nowTime.substring(4, 6));// 现在月
					if (O.ckSt(implTime)) {
						if (implTime.contains(".") || implTime.contains("-")) {
							String[] startTime = implTime.split("\\.");
							if (startTime.length < 2) {
								startTime = implTime.split("-");
							}
							String tempStartYear = startTime[0];
							String tempStartMoonth = startTime[1];
							if (O.ckNm(tempStartYear) && O.ckNm(tempStartMoonth)) {
								startYear = Integer.valueOf(tempStartYear);// 施工年
								startMoonth = Integer.valueOf(tempStartMoonth);// 施工月
							}
						} else {
							if (O.ckNm(implTime)) {
								startYear = Integer.valueOf(implTime);// 施工年
							}
						}
					}

					if (O.ckSt(endTime)) {
						if (endTime.contains(".") || endTime.contains("-")) {
							String[] _endTime = endTime.split("\\.");
							if (_endTime.length < 2) {
								_endTime = endTime.split("-");
							}
							String tempEndYear = _endTime[0];
							String tempEndMoonth = _endTime[1];
							if (O.ckNm(tempEndYear) && O.ckNm(tempEndMoonth)) {
								endYear = Integer.valueOf(tempEndYear);// 施工年
								endMoonth = Integer.valueOf(tempEndMoonth);// 施工月
							}
						} else {
							if (O.ckNm(endTime)) {
								endYear = Integer.valueOf(endTime);// 施工年
							}
						}
					}

					if (0 == startYear) {
						plan = "储备";
					} else if (0 != startYear && 0 == endYear) {
						plan = "在建";
					} else {
						if (((startYear < nowYear) || (startYear == nowYear && startMoonth <= nowMoonth))
								&& ((nowYear == endYear && nowMoonth <= endMoonth) || (nowYear < endYear))) {
							plan = "在建";
						} else if (nowYear > endYear || (nowYear == endYear && nowMoonth > endMoonth)) {
							plan = "完成";
						}
					}

					String remarks = null;
					if (O.ckSt(list.get(18))) {
						remarks = this.removeSymbols(list.get(18).trim());
					}

					Project p = pd.project(projectName, s);
					if (null != p) {
						if (O.ckSt(implTime)) {
							String _startMoonth = "";
							if (startMoonth < 10) {
								_startMoonth = "0" + startMoonth;
							} else {
								_startMoonth = startMoonth + "";
							}
							p.setImpl_time(startYear + "-" + _startMoonth);
						} else {
							p.setImpl_time("");
						}
						p.setPlan(plan);
						p.setRemarks(remarks);

						switch (p.getPlan()) {
						case "完成":
							p.setHistory(Stct.HISTORY_IS);
							break;
						default:
							p.setHistory(Stct.HISTORY_NOT);
							break;
						}

						p.setCheckout((short) 1);
						p.setUpdate_time(O.getTimestamp3());

						s.update(p);
					}
				}
			}
			SessionProvider.commitSession(s);
		} catch (Exception e) {
			SessionProvider.rollback(s);
			e.printStackTrace();
		}
	}

	/**
	 * 批量添加项目转结完整数据
	 * 
	 * @param user
	 * @param tempList
	 */
	public Map<String, Integer> addMoreProjectSwerve(User user, List<List<String>> tempList) {
		Session s = null;
		try {
			tempList.remove(0);
			tempList.remove(0);
			tempList.remove(0);
			tempList.remove(0);
			tempList.remove(0);
			tempList.remove(0);
			Map<String, Integer> endMap = new HashMap<String, Integer>();
			s = SessionProvider.getSession();
			for (List<String> list : tempList) {
				if (null != list
						&& O.ckLt(list)
						&& O.ckSt(list.get(1))
						&& (O.ckSt(list.get(8)) || O.ckSt(list.get(9)) || O.ckSt(list.get(10)) || O.ckSt(list
								.get(12)))) {
					String projectName = this.removeSymbols(list.get(1).trim());
					String desc = this.removeSymbols(list.get(8).trim());// 项目简介
					String mgrDepart = this.removeSymbols(list.get(9).trim());// 主管部门
					String buildSide = this.removeSymbols(list.get(10).trim());// 建设部门
					String area = this.removeSymbols(list.get(12).trim());// 建设部门
					Double fund = null;// 总投资
					if (O.ckSt(list.get(2))) {
						fund = Double.valueOf(this.removeSymbols(list.get(2).trim()));
					}

					StringBuffer fundPlan = new StringBuffer();// 资金来源
					if (null != list.get(13) && O.ckSt(list.get(13))) {
						fundPlan.append("总计：" + this.removeSymbols(list.get(13)) + "；");
					}
					if (null != list.get(14) && O.ckSt(list.get(14))) {
						fundPlan.append("国家资金投入：" + this.removeSymbols(list.get(14)) + "；");
					}
					if (null != list.get(15) && O.ckSt(list.get(15))) {
						fundPlan.append("省政策资金（含债券）投入：" + this.removeSymbols(list.get(15)) + "；");
					}
					if (null != list.get(17) && O.ckSt(list.get(17))) {
						fundPlan.append("市场化方式投入——结转项目：" + this.removeSymbols(list.get(17)) + "；");
					}
					if (null != list.get(18) && O.ckSt(list.get(18))) {
						fundPlan.append("市场化方式投入——新建项目：" + this.removeSymbols(list.get(18)) + "；");
					}
					if (null != list.get(19) && O.ckSt(list.get(19))) {
						fundPlan.append("地铁、土储及棚改封闭运作投入：" + this.removeSymbols(list.get(19)) + "；");
					}
					if (null != list.get(20) && O.ckSt(list.get(20))) {
						fundPlan.append("市本级城建资金投入：" + this.removeSymbols(list.get(20)) + "；");
					}
					if (null != list.get(21) && O.ckSt(list.get(21))) {
						fundPlan.append("其他（银行贷款）投入：" + this.removeSymbols(list.get(21)) + "；");
					}
					if (null != list.get(22) && O.ckSt(list.get(22))) {
						fundPlan.append("区（政策区）投入：" + this.removeSymbols(list.get(22)) + "；");
					}
					if (null != list.get(23) && O.ckSt(list.get(23))) {
						fundPlan.append("企业及社会化投入：" + this.removeSymbols(list.get(23)) + "；");
					}

					String time = null;
					if (list.size() >= 26 && null != list.get(25) && !list.get(25).equals("")
							&& !list.get(25).equals("0") && !list.get(25).equals("0.0")) {
						time = this.removeSymbols(list.get(25).trim());
					}

					// String sign = null;// 备注
					// if (list.size() >= 27 && null != list.get(26)) {
					// sign = this.removeSymbols(list.get(26));
					// }
					String sign = null;// 备注
					if (list.size() >= 24 && null != list.get(23)) {
						sign = this.removeSymbols(list.get(23));
					}

					String implTime = null;// 施工时间
					String endTime = null;// 停工时间
					if (null != time && time.contains("-")) {
						String[] _time = time.split("-");
						implTime = _time[0];
						endTime = _time[1];
					}

					String plan = "储备";// 项目状态
					int startYear = 0;
					int startMoonth = 1;
					int endYear = 0;
					int endMoonth = 12;
					if (O.ckSt(implTime)) {
						if (implTime.contains(".")) {
							String[] startTime = implTime.split("\\.");
							String tempStartYear = startTime[0];
							String tempStartMoonth = startTime[1];
							if (O.ckNm(tempStartYear) && O.ckNm(tempStartMoonth)) {
								startYear = Integer.valueOf(tempStartYear);// 施工年
								startMoonth = Integer.valueOf(tempStartMoonth);// 施工月
							}
						} else {
							if (O.ckNm(implTime)) {
								startYear = Integer.valueOf(implTime);// 施工年
							}
						}
					}

					if (O.ckSt(endTime)) {
						if (endTime.contains(".")) {
							String[] _endTime = endTime.split("\\.");
							String tempEndYear = _endTime[0];
							String tempEndMoonth = _endTime[1];
							if (O.ckNm(tempEndYear) && O.ckNm(tempEndMoonth)) {
								endYear = Integer.valueOf(tempEndYear);// 施工年
								endMoonth = Integer.valueOf(tempEndMoonth);// 施工月
							}
						} else {
							if (O.ckNm(endTime)) {
								endYear = Integer.valueOf(endTime);// 施工年
							}
						}
					}

					if (0 == startYear) {
						plan = "储备";
					} else if (0 != startYear && 0 == endYear) {
						plan = "在建";
					} else {
						String nowTime = O.getTimestamp2();
						int nowYear = Integer.valueOf(nowTime.substring(0, 4));// 现在年
						int nowMoonth = Integer.valueOf(nowTime.substring(4, 6));// 现在月
						if (((startYear < nowYear) || (startYear == nowYear && startMoonth <= nowMoonth))
								&& ((nowYear == endYear && nowMoonth <= endMoonth) || (nowYear < endYear))) {
							plan = "在建";
						} else if (nowYear > endYear || (nowYear == endYear && nowMoonth > endMoonth)) {
							plan = "完成";
						}
					}

					// Project p = new Project();
					// Project project = pd.project(projectName, s);
					// if (null != project) {
					// Project project2 = pd.project(projectName + "_【结转】", s);
					// if (null != project2) {
					// p = project2;
					// } else {
					// p = project;
					// }
					// }

					Project p = new Project();
					if (28 <= list.size() && null != list.get(27) && O.ckSt(list.get(27))) {
						int pid = Integer.valueOf(this.removeSymbols(list.get(27)));
						if (0 != pid) {
							p = (Project) super.getObjectById(pid, Project.class);
							if (null == p) {
								p = new Project();
							}
						}
					} else {
						Project project = pd.project(projectName, s);
						if (null != project && null != project.getId()) {
							p.setName(projectName + "_【结转】");
						} else {
							p.setName(projectName);
						}
						p.setInput_time(O.getTimestamp3());
						p.setIspass(Stct.ISPASS_NOT);
						p.setComment((short) 1);
					}
					p.setFund(fund);
					p.setMgr_depart(mgrDepart);
					p.setBuild_side(buildSide);
					p.setUser_id(user.getId());
					p.setDescription(desc);
					p.setFund_plan(fundPlan.toString());
					p.setCheckout((short) 1);
					p.setSign(sign);
					p.setPlan(plan);
					p.setUpdate_time(O.getTimestamp3());

					if (O.ckSt(implTime)) {
						String _startMoonth = "";
						if (startMoonth < 10) {
							_startMoonth = "0" + startMoonth;
						} else {
							_startMoonth = startMoonth + "";
						}
						p.setImpl_time(startYear + "-" + _startMoonth);
					} else {
						p.setImpl_time("");
					}

					switch (p.getPlan()) {
					case "完成":
						p.setHistory(Stct.HISTORY_IS);
						break;
					default:
						p.setHistory(Stct.HISTORY_NOT);
						break;
					}

					p.setArea(area);

					if (null != p.getId()) {
						s.update(p);
					} else {
						s.save(p);
					}
					// if (28 <= list.size() && null != list.get(27) &&
					// O.ckSt(list.get(27))) {
					// s.update(p);
					// } else {
					// s.save(p);
					// }

					endMap.put(projectName, p.getId());

					// if (null != p.getId()) {
					// s.update(p);
					// } else {
					// s.save(p);
					// }
				}
			}
			SessionProvider.commitSession(s);
			return endMap;
		} catch (Exception e) {
			SessionProvider.rollback(s);
			e.printStackTrace();
			return null;
		}
	}

	/**
	 * 批量修改项目类别
	 * 
	 * @param fid
	 *            :一级分类
	 * @param sid
	 *            :二级分类
	 * @param tid
	 *            :三级分类
	 * @param pids
	 *            :项目IDS
	 */
	public void updateMoreCategory(int fid, int sid, int tid, String pids) {
		int[] _pids = O.getIntValues(pids);
		for (int id : _pids) {
			Project p = (Project) super.getObjectById(id, Project.class);
			if (null != p) {
				p.setFirst_category_id(fid);
				p.setSecond_category_id(sid);
				p.setThird_category_id(tid);
				p.setUpdate_time(O.getTimestamp3());
				super.updateObject(p);
			}
		}
	}

	/**
	 * 获取项目类别为空的数据
	 * 
	 * @return
	 */
	public List<Project> listProjectCategory() {
		Session s = SessionProvider.getSession();
		List<Project> pList = pd.listProjectCategory(s);
		SessionProvider.commitSession(s);
		return pList;
	}

	/**
	 * 去除特殊符号
	 * 
	 * @param str
	 * @return
	 */
	public String removeSymbols(String str) {
		if (!O.ckSt(str)) {
			return null;
		}
		if (str.contains("　")) {
			str = str.replaceAll("　", "");
		} else if (str.contains(" ")) {
			str = str.replaceAll(" ", "");
		} else if (str.contains("\n")) {
			str = str.replaceAll("\n", "");
		} else if (str.contains("\r")) {
			str = str.replaceAll("\r", "");
		}

		return str;
	}
}